package com.zhentao.controller;


import com.zhentao.model.common.dtos.PermissionResult;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.pojo.management.dto.req.SysUserDto;
import com.zhentao.model.common.pojo.users.param.UserInfoDto;
import com.zhentao.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mp
 * @since 2025-01-03
 */
@RestController
@RequestMapping("/user/info")
@CrossOrigin(origins = "http://localhost:5173")
public class UserInfoController {
    @Autowired
    private IUserInfoService userInfoService;

    /**
     * @description  admin -- user -- login
     * @author mhy
     * @date    2024/12/26 19:20
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @PostMapping("/login")
    public ResponseResult login(@RequestBody SysUserDto sysUser) {
        return userInfoService.login(sysUser);
    }

    /**
     * @description  获取用户信息
     * @author mhy
     * @date    2024/12/26 20:51
     * @param
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @GetMapping("/userInfo")
    public ResponseResult userInfo() {
        return userInfoService.userInfo();
    }

    /**
     * @description  退出登录
     * @author mhy
     * @date    2024/12/27 8:58
     * @param
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @GetMapping("/logout")
    public ResponseResult logout() {
        return userInfoService.logout();
    }

    @GetMapping("/sys/coupon/select")
    public PermissionResult csRun() {
        return userInfoService.csRun();
    }


    /**
     * @description  管理端 用户注册数量 活跃数量
     * @author mhy
     * @date    2024/12/31 16:07
     * @param
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
//    @GetMapping("/count")
//    public ResponseResult initUserCount(){
//        return userInfoService.initUserCount();
//    }
//

    /**
     * @description  获取用户信息
     * @author mhy
     * @date    2024/12/27 8:58
     */
    @GetMapping("/getUserList")
    public PermissionResult getUserList(@RequestParam(value = "userName",required = false) String userName){
        return userInfoService.getUserList(userName);
    }


    /**
     * @description  将用户加入黑名单
     * @author mhy
     * @date    2024/12/27 8:58
     */
    @GetMapping("/addBlackList")
    public PermissionResult addBlackList(@RequestParam(value = "userId",required = false)Integer userId){
        return userInfoService.addBlackList(userId);
    }

    /**
     * @deprecated  获取角色信息
     * @author mhy
     * @date    2024/12/27 8:58
     */
    @GetMapping("/getRoleList")

    public PermissionResult getRoleList(){
        return userInfoService.getRoleList();
    }

    /**
     * @description  修改用户
     * @author mhy
     * @date    2024/12/27 8:58
     */
    @PostMapping("/updateUser")
    public PermissionResult updateUser(@RequestBody UserInfoDto dto){
        return userInfoService.updateUser(dto);
    }
    @PostMapping("/registry")
    /**
     * @description:增加用户
     * @author: muhaoyang
     * @date: 2025/1/5 22:48
     * @param: [sysUserDto]
     * @return: com.zhentao.model.common.dtos.ResponseResult
     **/
    public ResponseResult registry(@RequestBody UserInfoDto userInfoDto){
        return userInfoService.registry(userInfoDto);
    }

    @DeleteMapping("/delete")
    /**
     * @description:删除用户
     * @author: muhaoyang
     * @date: 2025/1/6 10:10
     * @param: [userId]
     * @return: com.zhentao.model.common.dtos.ResponseResult
     **/
    public ResponseResult delete(@RequestParam(value = "userId",required = false)Integer userId){
        return userInfoService.deleteUser(userId);
    }

}

